﻿using System;
using UnityEngine;
using Unity.Entities;
using Unity.Mathematics;
using Jinndev.Tile2D;

namespace Jinndev {

    /// <summary>
    /// 用于TileLayer中
    /// </summary>
    public abstract class TileLayerHandler {

        public abstract EntityManager EntityManager { get; }

        /// <summary>
        /// 创建Entity方法
        /// </summary>
        public abstract Entity CreateTileEntity(TileLayer layer, Guid guid, int2 startIndex, RenderConfig renderConfig);

        /// <summary>
        /// 是否需要更新邻居
        /// </summary>
        public abstract bool NeedUpdateNeighbours(TileLayer layer, Tile mainTile, Entity entity, RenderConfig renderConfig);

        /// <summary>
        /// 更新Tile和Entiy，在创建后和更新时调用
        /// </summary>
        public abstract void UpdateTile(TileLayer layer, in Tile[,] tiles, Tile mainTile, Entity entity, RenderConfig renderConfig);

        /// <summary>
        /// 是否可以替换当前Tile
        /// </summary>
        public abstract bool CanReplaceTile(TileLayer layer, RenderConfig renderConfig, Tile curTile);

        /// <summary>
        /// 在自己和所有邻居执行完UpdateTile之后调用，不包含邻居
        /// </summary>
        public virtual void AfterUpdateTile(TileLayer layer, Tile[,] tiles, Tile mainTile, Entity entity, RenderConfig renderConfig) {

        }

        /// <summary>
        /// 销毁全部实体方法，返回是否中止默认的销毁Entity方法
        /// </summary>
        /// <returns>是否中止默认的销毁Entity方法</returns>
        public abstract bool DestroyAllEntities();

        /// <summary>
        /// 销毁Tile前执行，返回是否中止默认的销毁Entity方法
        /// </summary>
        public virtual bool BeforeDestroyTile(TileLayer layer, Tile mainTile, Entity entity) {
            return false;
        }


    }

}
